package com.songlanyun.modules.goods.model.vo;

import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.type.TypeReference;
import com.songlanyun.common.drive.ValueObject;
import com.songlanyun.common.exception.RRException;
import com.songlanyun.common.utils.custom.ClassConvertUtils;
import com.songlanyun.modules.goods.entity.Goods;
import com.songlanyun.modules.goods.entity.GoodsAuthShop;
import com.songlanyun.modules.goods.model.values.SkuSet;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 商品规格组件Vo
 */
@Data
public class SkuComItemVo implements ValueObject {

    /**
     *
     */
    @TableId
    private Long id;
    /**
     * 商品id
     */
    private Long goodsId;
    /**
     * 单品id
     */
    private Long singleGoodsId;

    /**
     * 单品码
     */
    private String singleGoodsCode;

    /**
     * 销售价
     * 1、如果是活动就是活动价
     * 2、如果是普通商品就是销售价
     */
    private BigDecimal salePrice;
    /**
     * 市场价
     */
    private BigDecimal marketPrice;
    /**
     * 重量
     */
    private BigDecimal weight;
    /**
     * 体积
     */
    private BigDecimal volume;
    /**
     * 商品规格编码
     */
    private String barCode;
    /**
     * 兑换积分
     */
    private BigDecimal exchangePoint;
    /**
     * 封面图片
     */
    private String cover;

    /**
     * 规格名（蓝色,175,男）
     */
    private String skuSetName;

    /**
     * 所有属性值哈希值
     * 1111|1234|4556
     */
    private String skuHashCode;

    /**
     * 单品可用库存
     */
    private Integer ableStock = 0;

    private List<SkuSet> skuSets;

    @JsonIgnore
    private String skuSetValue;
    public void setSkuSetValue(String skuSetValue) {
        this.skuSetValue  = skuSetValue;
        if (StringUtils.isEmpty(this.skuSetValue)) {
            this.skuSets = new ArrayList<>();
        } else {
            try {
                this.skuSets = ClassConvertUtils.stringToClassSnake(skuSetValue, new TypeReference<List<SkuSet>>() {
                });
            } catch (IOException e) {
                throw new RRException("商品规格无法转Map");
            }
        }
    }
}
